﻿<%@ Page Title="" Language="C#" MasterPageFile="~/layout/admin.Master" AutoEventWireup="true" CodeBehind="EditService.aspx.cs" Inherits="SinhNhat.admin.EditService" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentHead" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentMain" runat="server">

    <script type="text/javascript">
        function Valid() {
            var valid = true;

            var errorStr = "";
            var txtName = document.getElementById("<%=txtName.ClientID %>");
            //ctl00_ContentMain_txtDescription
            var txtContent = CKEDITOR.instances.<%=txtDescription.ClientID %>.getData();

            if (txtName.value == '') {
                txtName.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Nhập tên dịch vụ</li>";
                txtName.focus();
                valid = false;
            }
            else {
                txtName.setAttribute('class', '');
            }

//            if (txtURL.value == '') {
//                txtURL.setAttribute('class', 'textValid');
//                errorStr += "<li style='color:red;'>Nhập URL</li>";
//                txtURL.focus();
//                valid = false;
//            }
//            else {
//                txtURL.setAttribute('class', '');
//            }

            if (txtContent == '') {
                errorStr += "<li style='color:red;'>Nhập nội dung</li>";
                valid = false;
            }

            var myselect = document.getElementById("<%=lbCategory.ClientID %>");            
            var i;
            for (i=0; i < myselect.options.length; i++){
                if (myselect.options[i].selected==true){
                    break;
                }
            }

            if(i == myselect.options.length){
                myselect.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Chọn loại dịch vụ</li>";
                myselect.focus();
                valid = false;
            }
            else
            {
                myselect.setAttribute('class', '');
            }

            if (valid == false) {
                errorStr = "<ul>" + errorStr + "</ul>";
            }

            document.getElementById("divError").innerHTML = errorStr;
            return valid;
        }
    </script>
    
    <asp:HiddenField ID="hdServiceID" runat="server" />
    <asp:HiddenField ID="hdUrlOld" runat="server" />

    <h2>
        <asp:Label ID="lblHeader" runat="server" />
    </h2>

    <table>
        <tr>
            <td style="width:100px;">Tên dịch vụ</td>
            <td>
                <asp:TextBox ID="txtName" runat="server" Width="500px" />
            </td>
        </tr>
        <%--<tr>
            <td>URL</td>
            <td>
                <asp:TextBox ID="txtUrl" runat="server" Width="500px" />
            </td>
        </tr>--%>
        <tr>
            <td>Hình ảnh</td>
            <td>
                <asp:FileUpload ID="fuProduct" runat="server" />
                <asp:Image ID="imgProduct" runat="server" Visible="false" Width="300px" />
                <asp:Label ID="lblErrorImg" runat="server" ForeColor="Red" Visible="false" Text="Image is not correct" />
            </td>
        </tr>
        <tr>
            <td>Mô tả</td>
            <td>
                <CKEditor:CKEditorControl ID="txtDescription" runat="server" Width="666px" Height="400px"></CKEditor:CKEditorControl>
            </td>
        </tr>
        <tr>
            <td>Loại dịch vụ</td>
            <td>
                <asp:ListBox ID="lbCategory" runat="server" Width="300px" Height="300px" />
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <div id="divError"></div>
                <asp:Literal ID="lblError" runat="server" Text="<ul><li style='color:red;'>URL đã tồn tại</li></ul>" Visible="false" Mode="PassThrough" />
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <asp:Button ID="btnSave" runat="server" OnClientClick="return Valid();" Text="Save" CssClass="button_colour round_all" />

            </td>
        </tr>
    </table>

</asp:Content>
